package org.jeecg.modules.api.wlhy.carrier;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.hycarrier.entity.HyCarrier;
import org.jeecg.modules.wlhy.hycarrier.service.IHyCarrierService;
import org.jeecg.modules.wlhy.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description: 承运商
 * @Author: duanlikao
 * @Date: 2020-12-01
 * @Version: V1.0
 */
@Api(tags = "app承运商")
@RestController
@RequestMapping("/api/wlhy/carrier")
@Slf4j
public class ApiCarrierController extends JeecgController<HyCarrier, IHyCarrierService> {
    @Autowired
    private IHyCarrierService hyCarrierService;

    @Autowired
    private UserUtil userUtil;

//    @AutoLog(value = "承运商-列表查询")
    @ApiOperation(value = "承运商-列表查询", notes = "承运商-列表查询")
    @GetMapping(value = "/all")
    public Result<?> allList(HyCarrier hyCarrier, HttpServletRequest req) {
        QueryWrapper<HyCarrier> queryWrapper = QueryGenerator.initQueryWrapper(hyCarrier, req.getParameterMap());
        queryWrapper.eq("iz_used", "1");
        List<HyCarrier> list = hyCarrierService.list(queryWrapper);
        return Result.OK(list);
    }

    @GetMapping(value = "/customerlist")
    public Result<?> customerList(HyCarrier hyCarrier, HttpServletRequest req) {
        HyCustomer customer = userUtil.getCustomer();
        if (customer == null) {
            return Result.error("未获取到货主信息");
        }
        QueryWrapper<HyCarrier> queryWrapper = QueryGenerator.initQueryWrapper(hyCarrier, req.getParameterMap());
        queryWrapper.eq("iz_used", "1");
        queryWrapper.eq("customer_id", customer.getId());
        List<HyCarrier> list = hyCarrierService.list(queryWrapper);
        return Result.OK(list);
    }

    /**
     * 获取车队长银行卡查询当月提现金额合计
     *
     * @param id 银行卡id
     * @return
     */
    @GetMapping(value = "/getAmountMonthById")
    public Result<?> getAmountMonthById(@RequestParam(name = "id") String id) {

        if(StringUtils.isNotEmpty(id)){
            Integer AmountMonth = hyCarrierService.getAmountMonthById(id);

            if (AmountMonth!=null){
                //大于15万预警
                if (AmountMonth >= 150000) {
                    return Result.OK("1");
                }else{
                    return Result.OK("0");
                }
            }else{
                return Result.OK("0");
            }

        }else{
            return Result.error("银行卡id不允许为空!");
        }
    }
}
